<template>
  <div class="app-main">
    <el-card shadow="never">
      <el-row>
        <div class="rank-title">
          <i class="el-icon-medal-1">员工绩效排行</i>
        </div>
      </el-row>
      <el-row class="table-container">
        <el-table :data="tableData" v-loading="loading" element-loading-text="数据加载中···" stripe style="width: 100%" size="medium" max-height="670">
          <el-table-column label="序号" type="index"></el-table-column>
          <el-table-column label="员工姓名" prop="username" show-overflow-tooltip></el-table-column>
          <el-table-column label="已完成单数" prop="finish" show-overflow-tooltip></el-table-column>
          <el-table-column label="未完成单数" prop="unfinish" show-overflow-tooltip></el-table-column>
          <el-table-column label="总接单数" prop="totalorder" show-overflow-tooltip></el-table-column>
          <el-table-column label="总营收额" prop="totalrevenue" show-overflow-tooltip></el-table-column>
          <el-table-column label="排名" show-overflow-tooltip>
            <template slot-scope="scope">
              <i class="el-icon-s-flag" style="color: red"></i>
              <span>{{ scope.row.ranking }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <el-row class="pagination-container">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page.pageNo"
          :page-sizes="page.pageSizes"
          :page-size="page.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">
        </el-pagination>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import {getPerformanceList} from "@/api/performance";

export default {
  name: "index",
  data() {
    return {
      tableData: [],
      loading: false,
      page: {
        pageNo: 1,
        pageSizes: [10, 50, 100, 200, 500],
        pageSize: 10,
        total: 10
      },
    }
  },
  created() {
    this.queryData()
  },
  methods: {
    queryData() {
      this.loading = true
      let params = {
        pageNo: this.page.pageNo,
        pageSize: this.page.pageSize
      }
      getPerformanceList(params).then(response => {
        if(response.code === 200) {
          this.tableData = response.data.list
          this.page.total = response.data.total
        } else {
          this.$message.error(response.msg);
        }
        this.loading = false
      })
    },
    handleSizeChange(val) {
      this.page.pageSize = val
      this.page.pageNo = 1
      this.queryData()
    },
    handleCurrentChange(val) {
      this.page.pageNo = val
      this.queryData()
    }
  }
}
</script>

<style lang="scss" scoped>
.app-main {
  padding: 20px;
  box-sizing: border-box;

  .rank-title {
    display: flex;
    justify-content: center;
    font-size: 32px;
    letter-spacing: 5px;
    color: #FF69B4;
    margin-top: 10px;
  }

  .table-container {
    margin-top: 20px;
  }

  .pagination-container {
    margin: 20px 0;
    float: right;
  }
}
</style>
